var logOutLink = $('#logout-link');

var logOutLinkClick = function(sender) {
	sender.preventDefault();

	if (logOutLink.hasClass('disabled')) return;
	logOutLink.addClass('disabled');

	$.post(app.baseUrl() + 'index.php/home/logout').done(function(response) {
		var data = null;

		try {
			data = JSON.parse(response);
		}
		catch(ex) {
			console.info(response);
		}

		if (data != null) {
			if (data['logout'] != undefined &&
				data['logout'] != null) {
				if (data['logout']) window.location.replace(app.baseUrl());
			}
		}
	}).fail(function(response) {
		try {
			console.error(response);
		}
		catch (ex) {

		}
	}).always(function() {
		logOutLink.removeClass('disabled');
	});
};

$(document).ready(function() {
	logOutLink.unbind('click');
	logOutLink.click(logOutLinkClick);
});